package cn.geracomium.action;

import cn.geracomium.util.action.AbstractAction;
import cn.geracomium.util.web.SplitPageUtil;
import cn.gov.service.*;
import cn.gov.vo.MemberBase;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.lang.reflect.Member;
import java.text.SimpleDateFormat;

@Controller
@RequestMapping("pages/")
public class MemberAction extends AbstractAction {
    @Reference
    private IMemberBaseService memberBaseService;
    @Reference
    private IMemberStateService memberStateService;
    @Reference
    private IMemberInfoService memberInfoService;
    @Reference
    private IMemberEmergencyContactService memberEmergencyContactService;
    @Reference
    private IMemberHealthystateRelService memberHealthystateRelService;
    @RequestMapping("member/member_list")
    public ModelAndView memberList() {
        SplitPageUtil spu = new SplitPageUtil("姓名:name|手机号码:phone|身份证:postionNumber", "files/member/member_list.action");


        ModelAndView mav = new ModelAndView("pages/files/member/member_list") ;
        mav.addAllObjects(this.memberBaseService.list(spu.getCurrentPage(), spu.getLineSize(), spu.getColumn(), spu.getKeyword()));
        mav.addAllObjects(this.memberStateService.list());
        return mav ;
    }
    @RequestMapping("member/member_show")
    public ModelAndView memberShow(Long memberId){
        ModelAndView mav = new ModelAndView("pages/files/member/member_show");
        mav.addObject(this.memberBaseService.get(memberId));
        mav.addObject(this.memberEmergencyContactService.getAllById(memberId));
        mav.addObject(this.memberInfoService.get(memberId));
        mav.addObject(this.memberHealthystateRelService.get(memberId));
        return mav;
    }
    @RequestMapping("member/member_update")
    public ModelAndView memberUpdate(Long memberId){
        ModelAndView mav = new ModelAndView("pages/files/member/member_update");
        mav.addObject(this.memberBaseService.get(memberId));
        mav.addObject(this.memberEmergencyContactService.getAllById(memberId));
        mav.addObject(this.memberInfoService.get(memberId));
        mav.addObject(this.memberHealthystateRelService.get(memberId));
        return mav;
    }
    @RequestMapping("member/member_edit")
    public boolean memberEdit(MemberBase memberBase){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(memberBase.getBirthday());
        System.err.println(format);
        System.err.println(memberBase.getBirthday());
        System.err.println(memberBase.getBirthday());
        System.err.println(memberBase.getBirthday());
        return this.memberBaseService.edit(memberBase);
    }
}
